| # Enhancements to java.lang.* and java.util.* in Java 2 SDK v1.3 | Documentation Contents

> Version 1.3 of the Java 2 SDK included the following enhancements:

> > Classes `java.lang.Math` and `java.lang.StrictMath`
> > New Timer API
> > Enhanced Collections Framework
> > Virtual Machine Shutdown Hooks
> > New URL JAR File Caching

> Classes `java.lang.Math` and `java.lang.StrictMath`

> > The Java 2 Platform now contains two clases which provide API for performing general numeric operations.
> > - `java.lang.StrictMath` - Class `java.lang.StrictMath` has the same API as old class `java.lang.Math`, which was present previous versions of the Java platform. Unlike class `Math`, however, `StrictMath` is defined to return bit-for-bit reproducible results in all implementations.
> > - `java.lang.Math` - Class `java.lang.Math` provides the same set of API as does class `StrictMath`. However, unlike some of the numeric functions of class `StrictMath`, all implementations of the equivalent functions of class `Math` are not defined to return the bit-for-bit same results, but can vary within specified constraints. This permits better-performing implementations where strict reproducibility is not required.

> New Timer API

> > Two new classes have been added to the Java 2 Platform to provide an API for a timer facility which can be used for purposes such as animations, human interaction timeouts, on-screen clocks and calendars, work-scheduling routines, reminder facilities, and more.
> > - `java.util.Timer`
> > - `java.util.TimerTask`
> > `Countdown.java` is a simple demo application that uses the new Timer API.

> Enhanced Collections Framework

> > The Collections Framework has these new convenience APIs:
> > - Added java.util.Collections.singletonList and java.util.Collections.singletonMap. Previously, there was a convenience implementation for singleton Set, but no corresponding implementation for List and Map. Both of these implementations proved desirable in practice.
> > - Added java.util.Collections.EMPTY_MAP. Previously, there were constant convenience implementations for the empty Set and List, but no corresponding implementation for Map.
> > The following special-purpose implementation has also been added:
> > - Added Map constuctor for WeakHashMap. The Map interface dictates that most Map implementations should have a "copy constructor" that takes a Map argument. WeakHashMap lacked such a constructor in the 1.2 release.

> Virtual Machine Shutdown Hooks

> > Sophisticated applications often require the ability to perform specific actions when the virtual machine shuts down, whether due to voluntary exit or involuntary termination. Typical actions include cleanly closing down network connections, saving session state, and deleting temporary files. Every major operating system provides the means for native applications to do this, though of course the details vary from platform to platform. Three methods have been added to `java.lang.Runtime` to provide a simple and portable interface to these facitilies. The new methods are:
> > - `addShutdownHook`
> > - `removeShutdownHook`
> > - `halt`
> > In addition, the `Runtime.exit` method has been revised. For more information, see Design of the Shutdown Hooks API.

> New URL JAR File Caching

> > The API of classes `java.util.zip` and `java.util.jar` have been enhanced with the addition of the following:
> > - `java.util.zip.OPEN_READ`
> > - `java.util.zip.OPEN_DELETE`
> > - `java.util.zip.ZipFile(File file, int mode)`
> > - `java.util.jar.JarFile(File file, boolean verify, int mode)`
> > The previous implementation of caching downloaded Jar files created problems for long-running server application and for RMI. Each open JarURLConnection creates a temporary local file that holds Jar-file date, and a JarFile object is created on top of the temporary file. Because the open file handle/descriptor on each temporary file was never closed, the files could quickly take up disk space for long-running server applications. The new API provides a solution for this problem by supporting a new "delete-on-close" mode for opening Zip and Jar files.

Copyright © 1999 Sun Microsystems, Inc. All Rights Reserved. Please send comments to: jdk-comments@java.sun.com |